package nl.infodation.emr.pricingservice.rulegeneration;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.eclipse.emf.mwe.core.resources.AbstractResourceLoader;
import org.eclipse.emf.mwe.internal.core.MWEPlugin;

public class ContextFirstResourceLoader extends AbstractResourceLoader {

	@Override
	public InputStream getResourceAsStream(String path) {
		return super.getResourceAsStream(path);
	}
	
	@Override
	public Class<?> loadClass(final String clazzName) {
		return super.loadClass(clazzName);
	}
	
	@Override
	public URL getResource(String path) {
		URL url = loadFromContextClassLoader(path);
		try {
			if (url == null || url.getContent() == null) {
				url = super.getResource(path);
			}
		}
		catch (IOException ioe) {}
		return url;
	}
	
	@Override
	protected Class<?> tryLoadClass(final String clazzName) throws ClassNotFoundException {
		return MWEPlugin.loadClass(MWEPlugin.ID, clazzName);
	}
}